import Vue from 'vue';
import App from './App.vue';
import router from './router';
import ElementUI from 'element-ui';
import VueI18n from 'vue-i18n';
import Print from 'vue-print-nb';
import { messages } from './components/common/i18n';
// import 'element-ui/lib/theme-chalk/index.css'; // 默认主题
import './assets/css/theme-green/index.css'; // 浅绿色主题
import './assets/css/icon.css';
import './components/common/directives';
import 'babel-polyfill';
import {isExistUser} from "./api/hospital/user";
import headerTop from  "./components/page/hospital/Header"
// import Echarts from 'vue-echarts';
// import 'echarts/lib/chart/bar';

let echarts=require('echarts/lib/echarts');
require('echarts/lib/chart/line');
require('echarts/lib/chart/bar')
require('echarts/lib/component/tooltip')
require('echarts/lib/component/title')
require('echarts/lib/component/legend')
require('echarts/lib/component/legendScroll')//图例滚动
//vue全局注入echarts
Vue.prototype.$echarts = echarts
Vue.component("header-view",headerTop);
Vue.config.productionTip = false;
Vue.use(VueI18n);
Vue.use(Print);
Vue.use(ElementUI, {
    size: 'small'
});
const i18n = new VueI18n({
    locale: 'zh',
    messages
});
//使用钩子函数对路由进行权限跳转
router.beforeEach((to, from, next) => {
    document.title = `${to.meta.title} | vue-situational`;
    //查询用户表是否已注册用户
    isExistUser().then((res) => {
        //已存在用户 登录页
         if (res.success==true){
                 //是否已登录
                 const role = localStorage.getItem('ms_userAcct');
                 /*未登录*/
                 if (role==null && to.path !== '/login') {
                     next('/login');
                 }else{
                     /*已登录*/
                     next();
                 }
         }else{
             if (to.path=='/isExistUser'){
                 next();
             }
         }
    }).catch(() => {
            this.$message({
                message:'跳转错误'
            });
        });;
});

new Vue({
    router,
    i18n,
    render: h => h(App)
}).$mount('#app');
